﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZX.SYS.Library;
using ZX.DBModule;

namespace ZX.SYS.Bussiness.Phrase
{
     public partial class BDatPhraseDetail: BLL.Extend.BaseBussnies<DatPhraseDetail>
    {
         public BDatPhraseDetail() { this.entity = new DatPhraseDetail(); }

        /// <summary>
        /// 通过ClassID获取PhraseClass实例
        /// </summary>
         /// <param name="PhraseID"></param>
        /// <returns></returns>
         public DatPhraseDetail GetDatPhraseDetailByID(Guid PhraseID)
        {
            return this.GetEntityById<DatPhraseDetail>(PhraseID);
        }

        /// <summary>
         /// 获取指定类型的PhraseDetail实例
        /// </summary>
        /// <param name="ClassValue"></param>
        /// <returns></returns>
         public IList<DatPhraseDetail> GetAllDatPhraseDetail(string ClassValue)
        {
            string s = "IsPause=0 and ClassID=(select [ClassID] from DatPhraseClass where ClassValue='" + ClassValue + "')";
            return this.GetEntityListByCondition<DatPhraseDetail>(s);
        }

        public override string CheckData(BaseEntity instance)
        {
            DatPhraseDetail entity = instance as DatPhraseDetail;
            if (string.IsNullOrEmpty(entity.PhraseValue))
            {
                return "字典类型值不能为空!";
            }
            if (IsExeists(entity))
            {
                return "该字典类型己存在!";
            }
            return base.CheckData(entity);
        }

        public override string CheckData()
        {
            return CheckData(this.entity);
        }

        public bool IsExeists(DatPhraseDetail entity)
        {
            return GetEntitysByCondition("ClassID ='" + entity.ClassID + "' and PhraseValue='" + entity.PhraseValue+ "'") != null;
        }

        /// <summary>
        /// 请假类型
        /// </summary>
        /// <returns></returns>
        public System.Data.DataTable  GetLeaveType()
        {
            System.Data.DataTable dt = null;
            dt = this.GetDataBySqlComm("select Name as DisplayMember,CONVERT(varchar(50),ID)+'|'+isnull(IsIncludeCalendar,'') as ValueMember from wkVacation where status='' or status is null");
            return dt;
        }
         
    }
}
